<?php

Yii::import('zii.widgets.CPortlet');
Yii::import('application.modules.user.components.*');

class LocationMenu extends CPortlet
{
    public function init()
    {
        /*$this->title = sprintf('%s <br /> %s: %s',
                               Yum::t('Usermenu'),
                               Yum::t('Logged in as'),
                               Yii::app()->user->data()->username);*/

        $this->contentCssClass = 'menucontent';
        return parent::init();
    }

    public function run()
    {
        $this->widget('YumMenu', array('items' => $this->getMenuItems()));

        parent::run();
    }

    public function getMenuItems()
    {
        $items = array();

        $regions = YumRegion::model()->findAll();
        foreach ($regions as $region) {
            $item = array();
            $item['label'] = Yum::t($region->name);
            $url= array();
            $cities=YumCity::model()->findAll('region_id=:regionId', array(':regionId'=>$region->id));
            foreach($cities as $city) {
                $item1 = array();
                $item1['label'] = Yum::t($city->name);
                $url1= array();
                $url1[] = $city->id;
                $item1['url'] = $url1;
                $url[]=$item1;
            }
            $item['items'] = $url;
            $items[] = $item;
        }
        return $items;
    }
}